home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_02 / portable / wnoutref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-29  |  4.0 KB  |  146 lines

  1. #ifndef NO_MEMORY_H
  2. #include <memory.h>
  3. #endif
  4.  
  5. #include <string.h>
  6.  
  7. #define    CURSES_LIBRARY    1
  8. #include <curses.h>
  9. #undef    wnoutrefresh
  10.  
  11. #ifdef PDCDEBUG
  12. char *rcsid_wnoutref = "$Header: C:\CURSES\portable\RCS\wnoutref.c 2.1 1993/06/18 20:21:47 MH Rel MH $";
  13. #endif
  14.  
  15.  
  16.  
  17.  
  18. /*man-start*********************************************************************
  19.  
  20.   wnoutrefresh()    - do effiecient refresh
  21.  
  22.   X/Open Description: (part of the wnoutrefresh() description.)
  23.      These two routines allow multiple updates with more efficiency
  24.      than wrefresh() alone.  In addition to all of the window
  25.      structures representing the terminal screen: a physical screen,
  26.      describing what is actually on the screen and a virtual screen,
  27.      describing what the programmer wants to have on  the screen.
  28.  
  29.      The wrefresh() function works by first calling wnoutrefresh(),
  30.      which copies the named window to the virtual screen.  It then
  31.      calls doupdate(), which compares the virtual screen to the
  32.      physical screen and does the actual update.  If the programmer
  33.      wishes to output several windows at once, a series of cals to
  34.      wrefresh() will result in alternating calls to wnoutrefresh()
  35.      and doupdate(), causing several bursts of output to the
  36.      screen.  By first calling wnoutrefresh() for each window, it
  37.      is then possible to call doupdate() once.  This results in
  38.      only one burst of output, with probably fewer total characters
  39.      transmitted and certainly less CPU time used.
  40.  
  41.   PDCurses Description:
  42.      In addition to the above, if REGISTERWINDOWS is TRUE when the
  43.      library was compiled, any windows registered (true by default
  44.      with PDCurses and _cursvar.refreshall is TRUE, then all
  45.      registered windows will be called via wnoutrefresh() before
  46.      the actual screen update begins.
  47.  
  48.   X/Open Return Value:
  49.      The doupdate() function returns OK on success and ERR on error.
  50.  
  51.   X/Open Errors:
  52.      No errors are defined for this function.
  53.  
  54.   Portability:
  55.      PDCurses    int wnoutrefresh( WINDOW* w );
  56.      X/Open Dec '88    int wnoutrefresh( WINDOW* w );
  57.      BSD Curses    int wnoutrefresh( WINDOW* w );
  58.      SYS V Curses    int wnoutrefresh( WINDOW* w );
  59.  
  60. **man-end**********************************************************************/
  61.  
  62. int    wnoutrefresh(register WINDOW *win)
  63. {
  64. register int        first;    /* first changed char on line */
  65. register int        last;    /* last changed char on line  */
  66.     int        begy;    /* window's place on screen   */
  67.     int        begx;
  68.     WINDOW*        s;
  69.     int        i;
  70.     int        j;
  71.     int        y;
  72.     int        x;
  73.     int        len;
  74.     chtype        attrs;
  75.  
  76. #ifdef PDCDEBUG
  77.     if (trace_on) PDC_debug("wnoutrefresh() - called\n");
  78. #endif
  79.  
  80.     if (win == (WINDOW *)NULL)
  81.         return( ERR );
  82.  
  83.     y = win->_cury;
  84.     x = win->_curx;
  85.     attrs = win->_attrs;
  86.     if (win->_title != NULL)
  87.         len = strlen(win->_title);
  88.     /*
  89.      * There may be a better place to implement window titles, but this
  90.      * seems to be the best place. -- Frotz
  91.      */
  92.     if ((len > 0) && (win->_title != NULL) && !(win->_flags & _SUBWIN))
  93.     {
  94.         wattrset(win, win->_title_attr);
  95.         mvwprintw(win, 0, (win->_title_ofs), "%s", (long) win->_title);
  96.         wmove(win, y, x);    /* restore cursor postion */
  97.         wattrset(win, attrs);    /* restore attributes      */
  98.     }
  99.  
  100.     if (win->_flags & _PAD)
  101.         return( ERR );
  102.  
  103.     s = curscr;
  104.     begy = win->_begy;
  105.     begx = win->_begx;
  106.  
  107.     for (i = 0, j = begy; i < win->_maxy; i++, j++)
  108.     {
  109.         if (win->_firstch[i] != _NO_CHANGE)
  110.         {
  111.             first = win->_firstch[i];
  112.             last = win->_lastch[i];
  113.  
  114.             memcpy(&(s->_y[j][begx + first]),
  115.                    &(win->_y[i][first]),
  116.                    (last - first + 1) * sizeof(chtype));
  117.  
  118.             first += begx;    /* s's min/max change positions */
  119.             last += begx;
  120.  
  121.             if (s->_firstch[j] != _NO_CHANGE)
  122.                 s->_firstch[j] = min(s->_firstch[j], first);
  123.             else
  124.                 s->_firstch[j] = first;
  125.  
  126.             s->_lastch[j] = max(s->_lastch[j], last);
  127.  
  128.             win->_firstch[i] = _NO_CHANGE;    /* updated now */
  129.         }
  130.         win->_lastch[i] = _NO_CHANGE;    /* updated now */
  131.     }
  132.  
  133.     if (win->_clear)
  134.     {
  135.         win->_clear = FALSE;
  136. /*        s->_clear = TRUE;*/
  137.     }
  138.  
  139.     if (!win->_leave)
  140.     {
  141.         s->_cury = win->_cury + begy;
  142.         s->_curx = win->_curx + begx;
  143.     }
  144.     return( OK );
  145. }
  146.